
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;


namespace BuildingBlocks.Infrastructure.Email
{
    public static class ServiceCollectionExtensions
    {
        public static IServiceCollection AddEmailModule(this IServiceCollection services, IConfiguration configuration)
        {
            services.Configure<EmailSettings>(configuration.GetSection("EmailSettings"));

            var settings = configuration.GetSection("EmailSettings").Get<EmailSettings>();

            if (settings!.Provider == EmailProvider.SendGrid)
            {
                services.AddScoped<IEmailSender, SendGridEmailSender>();
            }
            else
            {
                services.AddScoped<IEmailSender, MailKitEmailSender>();
            }

            return services;
        }
    }
}
